// import { rejects } from "assert";
// import { resolve } from "path";

// import { url } from "inspector"
const proxy={
  "/api":{
    target:"https://showme.myhope365.com",
    pathRewrite:false
  },
  "/music-api":{
    target:"https://showme.myhope365.com",
    pathRewrite:false
  }
}
export function request(options){
  return new Promise((resolve,rejects)=>{
    const header={
      "content-type": "application/x-www-form-urlencoded",
      "cookie":wx.getStorageSync('jsonid'),
      ...options.header
  }
  
  var apiarr=Object.keys(proxy)
  for(let key of apiarr){
    if(options.url.startsWith(key)){
      options.url=proxy[key].target+options.url
    }
  }
   wx.request({
     url: options.url,
     method:options.method,
     data:options.data,
     header,
     success:(res)=>{
      resolve(res)
     },
     fail:(eer)=>{
      rejects(err)
     }
   })
  })
}
export function post(url,data,options={}){
  return request({
    url,
    method:"POST",
    data,
    ...options
  })
}
export function get(url,options={}){
return request({
  url,
  method:"GET",
})
}